#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#define F first
#define S second
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ull P=131, q=177;
void solve()
{
	int n,m;
	cin>>n>>m;
	string s[n+1];
	for(int i=1;i<=n;i++) 
	{
		cin>>s[i];
	}
	string s1;
	unordered_map<ull,int> mp;
	for(int i=1;i<=m;i++)
	{
		cin>>s1;
		ull sum=0;
		ull ex=1;
		for(int j=0;j<s1.size();j++)
		{
			if(s1[j]=='/' || j==s1.size()-1)
			{
				if(j==s1.size()-1)
				{
					sum=sum*P+s1[j];
				}
				mp[sum]++;
			}

			sum=sum*P+s1[j];
			
		}
	}
	unordered_map<ull,int> um;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		ull sum=0;
		ull ex=1;
		for(int j=0;j<s[i].size();j++)
		{
			if(s[i][j]=='/' || j==s[i].size()-1)
			{
				if(j==s[i].size()-1)
				{
					sum=sum*P+s[i][j];
				}
				if(mp[sum]==0)
				{
					if(um[sum]==0)
					{
						cnt++;
					}

					um[sum]++;
					break;
				}
			}

			sum=sum*P+s[i][j];
		}
	}
	cout<<cnt<<endl;
}
int main()
{
	IOS;
	int T=1;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

